﻿
// MFCAppAJ64Dlg.cpp: 实现文件
//

#include "pch.h"
#include "framework.h"
#include "MFCAppAJ64.h"
#include "MFCAppAJ64Dlg.h"
#include "afxdialogex.h"
#include <vector>
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
#include "CAoJia.h"
CAoJia* g_AJ;

// 用于应用程序“关于”菜单项的 CAboutDlg 对话框

class CAboutDlg : public CDialogEx
{
public:
	CAboutDlg();

// 对话框数据
#ifdef AFX_DESIGN_TIME
	enum { IDD = IDD_ABOUTBOX };
#endif

	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV 支持

// 实现
protected:
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialogEx(IDD_ABOUTBOX)
{
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx)
END_MESSAGE_MAP()


// CMFCAppAJ64Dlg 对话框



CMFCAppAJ64Dlg::CMFCAppAJ64Dlg(CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_MFCAPPAJ64_DIALOG, pParent)
{
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CMFCAppAJ64Dlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
}

BEGIN_MESSAGE_MAP(CMFCAppAJ64Dlg, CDialogEx)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON1, &CMFCAppAJ64Dlg::OnBnClickedButton1)
	ON_BN_CLICKED(IDC_BUTTON2, &CMFCAppAJ64Dlg::OnBnClickedButton2)
	ON_BN_CLICKED(IDC_BUTTON3, &CMFCAppAJ64Dlg::OnBnClickedButton3)
END_MESSAGE_MAP()


// CMFCAppAJ64Dlg 消息处理程序

BOOL CMFCAppAJ64Dlg::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	// 将“关于...”菜单项添加到系统菜单中。

	// IDM_ABOUTBOX 必须在系统命令范围内。
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != nullptr)
	{
		BOOL bNameValid;
		CString strAboutMenu;
		bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);
		ASSERT(bNameValid);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// 设置此对话框的图标。  当应用程序主窗口不是对话框时，框架将自动
	//  执行此操作
	SetIcon(m_hIcon, TRUE);			// 设置大图标
	SetIcon(m_hIcon, FALSE);		// 设置小图标

	// TODO: 在此添加额外的初始化代码
	CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); 
	CString Str; 
	CStringA SA; 
	LONG AJD;
	//下面的代码中ARegJ64.dll和AoJia64.dll的路径要换成你自己的,如果是32位运行环境,插件名和插件路径都要改成32位的
	AJ = new CAoJia(L"d:\\AJ64\\ARegJ64.dll", L"d:\\AJ64\\AoJia64.dll");

	//或者像下面这样写,这种写法不用每次创建对象都调用CARegJ类的函数SetDllPathW,当然每次都调用也不会有问题
	//CARegJ::SetDllPathW(L"C:\\Users\\Administrator\\Desktop\\AJ64\\ARegJ64.dll", L"C:\\Users\\Administrator\\Desktop\\AJ64\\AoJia64.dll");
	//CAoJia AJ;
	
	if (AJ->hr == S_OK) {
		
		//SA = AJ.VerS(); cout << "版本号: " << SA << endl;
		//AfxMessageBox(L"注册成功，版本号: " + AJ.VerS());
		SA = AJ->GetModulePath(0, 0, L"d:\\AJ64\\AoJia64.dll", 0);
		//cout << "插件路径: " << SA << endl;
		CString strD;
		LONG loadR = AJ->LoadDict(1, L"D:\\AJ64\\AJ.txt");
		TRACE(L"loadR=%ld\n", loadR);
		g_AJ = AJ;
		//AJ.SetDict(1);
		
	}
	else {
		Str.Format(L"%08X", AJ->hr); 
		AfxMessageBox(L"创建对象失败,返回的错误码是: " + Str);
		//MessageBoxW(NULL, L"创建对象失败,返回的错误码是: " + Str, L"错误", MB_SETFOREGROUND);
	}

	return TRUE;  // 除非将焦点设置到控件，否则返回 TRUE
}

void CMFCAppAJ64Dlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialogEx::OnSysCommand(nID, lParam);
	}
}

// 如果向对话框添加最小化按钮，则需要下面的代码
//  来绘制该图标。  对于使用文档/视图模型的 MFC 应用程序，
//  这将由框架自动完成。

void CMFCAppAJ64Dlg::OnPaint()
{
	if (IsIconic())
	{
		CPaintDC dc(this); // 用于绘制的设备上下文

		SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);

		// 使图标在工作区矩形中居中
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// 绘制图标
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialogEx::OnPaint();
	}
}

//当用户拖动最小化窗口时系统调用此函数取得光标
//显示。
HCURSOR CMFCAppAJ64Dlg::OnQueryDragIcon()
{
	return static_cast<HCURSOR>(m_hIcon);
}



void CMFCAppAJ64Dlg::OnBnClickedButton1()
{
	if (g_AJ != nullptr) {
		long x, y;
		CString strD;		
		long result = g_AJ->FindStr(4, 1, 390, 164, L"迅雷", L"ffffff-000000|ffffff-000000", 1, 0, 0, 0, strD, x, y);
		TRACE(L"x=%ld,%d,%d\n", result, x, y);
		g_AJ->MoveTo(x, y);		
	}
	// TODO: 在此添加控件通知处理程序代码
}


void CMFCAppAJ64Dlg::OnBnClickedButton2()
{
	// TODO: 在此添加控件通知处理程序代码
	LONG htResult = g_AJ->KQHouTai(661652, L"GDI", L"WM", L"WM", L"", 0);
	TRACE(L"htResult=%ld\n", htResult);
	if (htResult) {
		long x, y;
		CString strD;
		long result = g_AJ->FindStr(8, 31, 1447, 857, L"地图", L"3ee0f4-000000|ffffff-000000", 1, 0, 0, 0, strD, x, y);
		TRACE(L"x=%ld,%d,%d\n", result, x, y);
		g_AJ->MoveTo(x, y);		
		g_AJ->LeftClick();
	}
	
}


void CMFCAppAJ64Dlg::OnBnClickedButton3()
{
	// TODO: 在此添加控件通知处理程序代码
	//LONG htResult = g_AJ->KQHouTai(923926, L"GDI", L"KRI", L"WM", L"", 0);
	std::vector<LONG> wins{ 661652,923926 };
	std::vector<CString> models{L"DX",L"KDI" ,L"KSI" ,L"KLI" ,L"KLI" ,L"WM" };	
	std::vector<CString> screen{ L"GDI",L"GDI1",L"GDI2",L"GDI3",L"DX" ,L"DX9" ,L"OL" };
	
	std::vector<LONG> types{ 1,2,3,4,5};
	for (LONG const& w : wins) {
		for (CString const& s : screen) {
			for (CString const& m : models) {
				for (LONG const& t : types) {
					LONG htResult = g_AJ->KQHouTai(w, s, m, L"WM", L"", t);
					if (!htResult) {
						TRACE(L"w=%ld,s=%s,m=%s,t=%ld,kResult=%ld KQHouTai fail\n", w, s, m, t, htResult);
						continue;
					}
					long kResult = g_AJ->KeyPress(81);
					//long kResult = g_AJ->KeyPressS(L"m");
					TRACE(L"w=%ld,s=%s,m=%s,t=%ld,kResult=%ld\n", w, s, m, t, kResult);
					Sleep(1000);
					long gb = g_AJ->GBHouTai();
					if (!gb) {
						TRACE(L"gb fail");
					}
				

				}
			}
		}
		
	}
	
}
